#include "StdAfx.h"
#include "AltiumCircuitSheetEntry.h"


CAltiumCircuitSheetEntry::CAltiumCircuitSheetEntry(void)
{
	m_dblDistanceFromTop = 0.0 ;
   
	m_ePortStyle = HORIZONTAL_NONE ; 

	m_ePortIOType = IO_UNSPECIFIED ;

	m_szName = _T("");

	m_dblBorderColor[0] = 0.0;
	m_dblBorderColor[1] = 0.0;	
	m_dblBorderColor[2] = 0.0;	

	m_dblFillColor[0] = 0.0;
	m_dblFillColor[1] = 0.0;
	m_dblFillColor[2] = 0.0;

	m_dblFontColor[0] = 0.0;
	m_dblFontColor[1] = 0.0;
	m_dblFontColor[2] = 0.0;

	m_eTextStyle = TEXT_STYLE_PREFIX; 

	m_eSide = SIDE_LEFT; 

	m_szArrowKind = _T("");
	m_circuitFont = NULL;

}

CAltiumCircuitSheetEntry::CAltiumCircuitSheetEntry( const CAltiumCircuitSheetEntry* pSheetEntry )
	:CCircuitUnit(pSheetEntry)
{
	m_dblDistanceFromTop = pSheetEntry->GetDistanceFromTop();

	m_ePortStyle = pSheetEntry->GetPortStyle(); 

	m_ePortIOType = pSheetEntry->GetPortIOType();

	m_szName = pSheetEntry->GetName();

	m_dblBorderColor[0] = pSheetEntry->GetBorderColorR();
	m_dblBorderColor[1] = pSheetEntry->GetBorderColorG();	
	m_dblBorderColor[2] = pSheetEntry->GetBorderColorB();	

	m_dblFillColor[0] = pSheetEntry->GetFillColorR();
	m_dblFillColor[1] = pSheetEntry->GetFillColorG();
	m_dblFillColor[2] = pSheetEntry->GetFillColorB();

	m_dblFontColor[0] = pSheetEntry->GetFontColorR();
	m_dblFontColor[1] = pSheetEntry->GetFontColorG();
	m_dblFontColor[2] = pSheetEntry->GetFontColorB();

	m_eTextStyle = pSheetEntry->GetTextStyle(); 

	m_eSide = pSheetEntry->GetSide(); 

	m_szArrowKind = pSheetEntry->GetArrowKind();

	m_circuitFont = pSheetEntry->GetCircuitFont();
}

CAltiumCircuitSheetEntry::CAltiumCircuitSheetEntry( CICircuit* pICircuit )
	: CCircuitUnit(pICircuit)
{
	m_dblDistanceFromTop = 0.0 ;

	m_ePortStyle = HORIZONTAL_NONE ; 

	m_ePortIOType = IO_UNSPECIFIED ;

	m_szName = _T("");

	m_dblBorderColor[0] = 0.0;
	m_dblBorderColor[1] = 0.0;	
	m_dblBorderColor[2] = 0.0;	

	m_dblFillColor[0] = 0.0;
	m_dblFillColor[1] = 0.0;
	m_dblFillColor[2] = 0.0;

	m_dblFontColor[0] = 0.0;
	m_dblFontColor[1] = 0.0;
	m_dblFontColor[2] = 0.0;

	m_eTextStyle = TEXT_STYLE_PREFIX; 

	m_eSide = SIDE_LEFT; 

	m_szArrowKind = _T("");
	m_circuitFont = NULL;

}


CAltiumCircuitSheetEntry::~CAltiumCircuitSheetEntry(void)
{
	if (m_circuitFont)
	{
		delete m_circuitFont;
	}
}

void CAltiumCircuitSheetEntry::Serialize( CArchive & ar )
{
	if (ar.IsStoring())
	{
		ar<<m_dblDistanceFromTop  ;
		ar<<m_ePortStyle ; 
		ar<<m_ePortIOType;
		CObj::WriteString(ar,m_szName);
		ar<<m_dblBorderColor[0] ;
		ar<<m_dblBorderColor[1] ;	
		ar<<m_dblBorderColor[2] ;	
		ar<<m_dblFillColor[0];
		ar<<m_dblFillColor[1];
		ar<<m_dblFillColor[2];
		ar<<m_dblFontColor[0];
		ar<<m_dblFontColor[1];
		ar<<m_dblFontColor[2];
		ar<<m_eTextStyle; 
		ar<<m_eSide; 
		CObj::WriteString(ar,m_szArrowKind);
		m_circuitFont->Serialize(ar);
	}
	else
	{
		ar>>m_dblDistanceFromTop  ;
		int nPortStyle(0);
		ar>>nPortStyle;
		m_ePortStyle  = (ePortStyle)nPortStyle; 
		int nIOType(0);
		ar>>nIOType;
		m_ePortIOType =(ePortIOType) nIOType;
		CObj::ReadString(ar,m_szName);
		ar>>m_dblBorderColor[0] ;
		ar>>m_dblBorderColor[1] ;	
		ar>>m_dblBorderColor[2] ;	
		ar>>m_dblFillColor[0];
		ar>>m_dblFillColor[1];
		ar>>m_dblFillColor[2];
		ar>>m_dblFontColor[0];
		ar>>m_dblFontColor[1];
		ar>>m_dblFontColor[2];
		int nTextStyle(0);
		ar>>nTextStyle;
		m_eTextStyle = (eTextStyle)nTextStyle; 
		int nSide(0);
		ar>>nSide;
		m_eSide = (eLeftRightSide)nSide; 
		CObj::ReadString(ar,m_szArrowKind);
		m_circuitFont = new CCircuitFont();
		m_circuitFont->Serialize(ar);
	}
	CCircuitUnit::Serialize(ar);
}

CObj * CAltiumCircuitSheetEntry::Clone() const
{
	return new CAltiumCircuitSheetEntry(this);
}

CDisplayObj * CAltiumCircuitSheetEntry::CreateDisplayObj( long lLayerId )
{
	CAltiumCircuitSheetEntryDisObj* pDisObj = new CAltiumCircuitSheetEntryDisObj(this);
	pDisObj->SetLayerId(lLayerId);
	return pDisObj;
}

void CAltiumCircuitSheetEntry::CalcBox()
{
	 
}

eCircuitUnitEntType CAltiumCircuitSheetEntry::GetUnitType() const
{
	return ALTIUM_CIRCUIT_SHEET_ENTRY;
}

double CAltiumCircuitSheetEntry::GetBorderColorR() const
{
	return m_dblBorderColor[0];
}

double CAltiumCircuitSheetEntry::GetBorderColorG() const
{
	return m_dblBorderColor[1];
}

double CAltiumCircuitSheetEntry::GetBorderColorB() const
{
	return m_dblBorderColor[2];
}

double CAltiumCircuitSheetEntry::GetFillColorR() const
{
	return m_dblFillColor[0];
}

double CAltiumCircuitSheetEntry::GetFillColorG() const
{
	return m_dblFillColor[1];
}

double CAltiumCircuitSheetEntry::GetFillColorB() const
{
	return m_dblFillColor[2];
}

double CAltiumCircuitSheetEntry::GetFontColorR() const
{
	return m_dblFontColor[0];
}

double CAltiumCircuitSheetEntry::GetFontColorG() const
{
	return m_dblFontColor[1];
}

double CAltiumCircuitSheetEntry::GetFontColorB() const
{
	return m_dblFontColor[2];
}

void CAltiumCircuitSheetEntry::SetBorderColorR( double colR)
{
	m_dblBorderColor[0]  = colR;
}

void CAltiumCircuitSheetEntry::SetBorderColorG( double colG)
{
	m_dblBorderColor[1] = colG;
}

void CAltiumCircuitSheetEntry::SetBorderColorB( double colB)
{
	m_dblBorderColor[2] = colB;
}

void CAltiumCircuitSheetEntry::SetFillColorR( double colR)
{
	m_dblFillColor[0] = colR;
}

void CAltiumCircuitSheetEntry::SetFillColorG( double colG)
{
	m_dblFillColor[1] = colG;
}

void CAltiumCircuitSheetEntry::SetFillColorB( double colB)
{
	m_dblFillColor[2] = colB;
}

void CAltiumCircuitSheetEntry::SetFontColorR( double colR)
{
	m_dblFontColor[0] = colR;
}

void CAltiumCircuitSheetEntry::SetFontColorG( double colG)
{
	m_dblFontColor[1] = colG;
}

void CAltiumCircuitSheetEntry::SetFontColorB( double colB)
{
	m_dblFontColor[2] = colB;
}